package com.woniuxy.microaftersaleserver.consultmag.mapper;

import com.github.pagehelper.PageInfo;
import com.woniuxy.microcommonserver.bean.aftersales_cyx.ConsultGoods;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ConsultMapper {
    /**
     * 添加咨询记录
     * @param consultGoods
     * useGeneratedKeys = true，主键自增
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "c.id"
    )
    @Insert("insert into consult_goods " +
            "(goods_id,gmt_create,user_id,consult_context,service_id,reply,gmt_modified,status,is_deleted)" +
            "values(#{c.goodsInfo.id},#{c.gmtCreate},#{c.userInfo.id},#{c.consultContext},#{c.customService.id},#{c.reply},#{c.gmtModified},#{c.status},0)")
    void addConsultRecord(@Param("c") ConsultGoods consultGoods);

    /**
     * 修改咨询记录
     * @param consultGoods
     */
    void updateConsultRecord(@Param("c") ConsultGoods consultGoods);

    /**
     * 删除记录
     * @param id
     */
    @Update("update consult_goods set is_deleted=1 where id=#{id}")
    void deleteConsultRecord(int id);

    /**
     * 根据字段模糊查询咨询记录
     * @param consultGoods
     * @return
     */
    List<Map> findByParams(@Param("c") ConsultGoods consultGoods);

    /**
     * 分页查询所有咨询记录
     * @param request
     * @param consultGoods
     * @return
     */
    List<ConsultGoods> findAll(@Param("p") PageRequest request, @Param("c") ConsultGoods consultGoods);
}
